# Spatial merge (point-to-polygon) for NPP
# To run this program, change the working directory as appropriate.

setwd("~/Dropbox (MIT)/Research/NYC421a")

### Install packages

install.packages("sf")

### Load packages

library(sf)
library(foreign)

### Load data

df <- read.csv("coords_latlong.csv")
attach(df)
points <- df[,2:3]

npp <- st_read("data/GIS_boundaries/npp/New_York_neighbourhoods.shp")

points_sf <- st_as_sf(points, coords = c("longitude","latitude"),crs = st_crs(npp))

### Assign NPP status

res <- as.data.frame(st_join(points_sf, npp, join = st_within))[2]
attach(res)
flag <- as.integer(!is.na(res))

newdata <- cbind(df$bbl, flag)
colnames(newdata) <- c("bbl","npp")

write.csv(newdata,file="data/raw/special_areas/npp_status.csv",row.names=FALSE)


